package com.bitnei.battery.examples;

import com.bitnei.battery.bean.dataBean.repair.CodeBean;
import com.bitnei.battery.bean.dataBean.repair.VehRepair;
import com.bitnei.battery.constants.BatterySpecies;

import java.util.ArrayList;
import java.util.List;

/**
 * @author czl
 * @email czl_nylg@163.com
 * @date 2019/10/14 17:58
 * @Version 1.0
 * @Description: 车辆维修示例
 */
public class VehRepairExample {

    public static void main(String[] args){
        //请求地址
        String url = "http://127.0.0.1:8999/bitnei/v1.0/battery/receiveReplaceOld";
        //组装数据
        List<VehRepair> repairList = new ArrayList<>();
        repairList.add(mockPackRepair());
        repairList.add(mockModuleRepair());
        //调用接口
        ApiUtilExample.callApi(url,repairList);
    }



    /**
     * 模拟车辆维修(电池包)
     * @return
     */
    private static VehRepair mockPackRepair(){
        VehRepair packRepair = new VehRepair();
        packRepair.setVin("LNBSCC3FXFR592905");
        packRepair.setBatterySpecies(BatterySpecies.P.getCode());
        packRepair.setReplaceDate("2018-03-20");
        packRepair.setWhereaboutsId("91430111MA4LXXXX");
        packRepair.setWhereaboutsId("电池报废企业");
        //维修换下
        packRepair.setOldCode("101PE00000");
        //维修换上
        packRepair.setNewCode("101PD00001");
        packRepair.setNewCodeBean(mockUpPack());
        return packRepair;
    }


    /**
     * 模拟车辆维修(电池模块)
     * @return
     */
    private static VehRepair mockModuleRepair(){
        VehRepair moduleRepair = new VehRepair();
        moduleRepair.setVin("LNBSCC3FXFR592905");
        moduleRepair.setBatterySpecies(BatterySpecies.P.getCode());
        moduleRepair.setReplaceDate("2018-03-20");
        moduleRepair.setWhereaboutsId("91430111MA4LXXXX");
        moduleRepair.setWhereaboutsId("电池报废企业");
        //维修换下
        moduleRepair.setOldCode("101MD00100");
        //维修换上
        moduleRepair.setNewCode("102MD00100");
        moduleRepair.setNewCodeBean(mockUpModule());
        return moduleRepair;
    }


    /**
     * 模拟换上电池包
     * @return
     */
    private static CodeBean mockUpPack(){
        CodeBean packBean = new CodeBean();
        packBean.setCode("101PD00001");
        packBean.setType(BatterySpecies.P.getCode());
        //构建电池包所含电池模块
        List<CodeBean> moduleBeanList = new ArrayList<>();
        CodeBean moduleBean = new CodeBean();
        moduleBean.setCode("101MD00100");
        moduleBean.setType(BatterySpecies.M.getCode());

        //构建模块所含电池单体
        List<CodeBean> cellList = new ArrayList<>();
        CodeBean cellBean = new CodeBean();
        cellBean.setType(BatterySpecies.C.getCode());
        cellBean.setCode("101CD00106");
        cellList.add(cellBean);
        moduleBean.setChildCodeList(cellList);

        moduleBeanList.add(moduleBean);
        packBean.setChildCodeList(moduleBeanList);
        return packBean;
    }


    private static CodeBean mockUpModule(){
        CodeBean moduleBean = new CodeBean();
        moduleBean.setCode("102MD00100");
        moduleBean.setType(BatterySpecies.M.getCode());

        //构建模块所含电池单体
        List<CodeBean> cellList = new ArrayList<>();
        CodeBean cellBean = new CodeBean();
        cellBean.setType(BatterySpecies.C.getCode());
        cellBean.setCode("102CD00106");
        cellList.add(cellBean);
        moduleBean.setChildCodeList(cellList);
        return moduleBean;
    }


}
